package com.zeng.jiudian.service.impl;

import com.zeng.jiudian.bean.OnlineModel;
import com.zeng.jiudian.dao.OnlineDao;
import com.zeng.jiudian.dao.impl.OnlineDaoImpl;
import com.zeng.jiudian.service.OnlineService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author JJ_yo
 * @Date 2020/7/30 - 17:48
 */
public class OnlineServiceImpl implements OnlineService
{
    @Override
    public int add(OnlineModel onlineModel)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();

        return onlineDao.add(onlineModel);
    }

    @Override
    public Map<String, List<OnlineModel>> findAll(OnlineModel onlineModel)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();
        List<OnlineModel> list = onlineDao.findAll(onlineModel);
        HashMap<String, List<OnlineModel>> map = new HashMap<>();
        map.put("list", list);

        return map;
    }

    @Override
    public int getCount(OnlineModel onlineModel)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();

        return onlineDao.getCount(onlineModel);
    }

    @Override
    public int delete(int id)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();

        return onlineDao.delete(id);
    }

    @Override
    public OnlineModel findById(int id)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();

        return onlineDao.findById(id);
    }

    @Override
    public int update(OnlineModel onlineModel)
    {
        OnlineDao onlineDao = new OnlineDaoImpl();

        if ("".equals(onlineModel.getName()))
        {
            onlineModel.setName(null);
        }
        if ("".equals(onlineModel.getPhone()))
        {
            onlineModel.setPhone(null);
        }
        if ("".equals(onlineModel.getStartdate()))
        {
            onlineModel.setStartdate(null);
        }
        if ("".equals(onlineModel.getEnddate()))
        {
            onlineModel.setEnddate(null);
        }
        if ("".equals(onlineModel.getRoomtype()))
        {
            onlineModel.setRoomtype(null);
        }
        if ("".equals(onlineModel.getIdea()))
        {
            onlineModel.setIdea(null);
        }

        return onlineDao.update(onlineModel);
    }
}
